package com.pubinfo.passbook.api.controller.contract;

import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.model.dto.contract.ApplyInvoiceParam;
import com.pubinfo.passbook.common.model.dto.contract.ContractIdParam;
import com.pubinfo.passbook.common.model.dto.contract.FeeListParam;
import com.pubinfo.passbook.common.model.http.eip.UserInfo;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.model.vo.contract.FapiaoDetailVo;
import com.pubinfo.passbook.common.model.vo.contract.FeeCollectionListVo;
import com.pubinfo.passbook.common.service.contract.TContractInvoiceApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author litiewang
 */
@Slf4j
@RestController
@Api(tags = "QGPB-开票查询")
@RequestMapping(value = "contractBilling")
public class ContractBillingController {
  
  @Resource
  private UserInfoService userInfoService;
  
  @Resource
  private TContractInvoiceApplyService tContractInvoiceApplyService;
  
  @PostMapping("useableContract")
  @ApiOperation(value = "可开票合同查询")
  public JsonResult<MyPage<FeeCollectionListVo>> useableContract(@RequestBody FeeListParam param) {
    UserInfo userInfo = userInfoService.getCurrentUserInfo();
    param.setRoleCode(userInfo.getRoleCode());
    param.setAcct(userInfoService.getCurrentAcct());
    param.setOrgId(userInfo.getOrgId());
    return JsonResult.success(new MyPage(tContractInvoiceApplyService.selectUseableList(param)));
  }
  
  @PostMapping("invoiceDetail")
  @ApiOperation(value = "合同发票详情")
  public JsonResult<List<FapiaoDetailVo>> invoiceDetail(@RequestBody @Valid ContractIdParam param) {
    return JsonResult.success(tContractInvoiceApplyService.invoiceDetail(param));
  }
  
  @PostMapping("applyInvoice")
  @ApiOperation(value = "统一平台订单受理")
  public JsonResult<Boolean> applyInvoice(@RequestBody @Valid ApplyInvoiceParam param) {
    return JsonResult.success(tContractInvoiceApplyService.orderApply(userInfoService.getCurrentUserInfo(), param));
  }
  
}
